package com.bootdo.xiao.suggest.suggest11;

import java.io.*;

/**
 * @Auther: liuj
 * @Date: 2019/5/23 17:05
 * @Description:序列化工具类，显示声明UID
 */
public class SerializationUtils {
    private static String FILE_NAME = "e:/obj.bin";
    //序列化
    public static void writeObject(Serializable serializable){
        try {
            System.out.println("开始序列化。。。。。");
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(FILE_NAME));
            oos.writeObject(serializable);
            oos.close();
            System.out.println("结束序列化。。。。。");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //反序列化
    public static Object readObject(){
        Object obj = null;
        try {
            System.out.println("开始反序列化。。。。。");
            ObjectInput oi = new ObjectInputStream(new FileInputStream(FILE_NAME));
            obj = oi.readObject();
            oi.close();
            System.out.println("结束反序列化。。。。。");
        }catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return obj;
    }
}
